<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/10/15
  Time: 15:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>role</title>
    <link type="text/css" rel="stylesheet" media="all" href="<%=request.getContextPath()%>/styles/global.css"/>
    <link type="text/css" rel="stylesheet" media="all" href="<%=request.getContextPath()%>/styles/global_color.css"/>
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script language="javascript" type="text/javascript">
        function deleteRole() {
            var r = window.confirm("确定要删除此角色吗？");
        }
    </script>
</head>
<body>
<!--Logo区域开始-->
<div id="header">
    <img src="../images/logo.png" alt="logo" class="left"/>
    <a href="<%=request.getContextPath()%>/admins/exit">[退出]</a>
</div>
<!--Logo区域结束-->
<!--导航区域开始-->
<div id="navi">
    <c:import url="../navigation.jsp"/>
    <script>
        var li = document.getElementById("menu").children;
        var title = document.getElementsByTagName('title')[0].textContent;
        for (let i = 0; i < li.length; i++) {
            if (li[i].children[0].className.startsWith(title)){
                li[i].children[0].className = title + '_on';
            }
        }
    </script>
</div>
<!--导航区域结束-->
<!--主要区域开始-->
<div id="main">
    <form action="/role/role_list_all" method="get">
        <!--查询-->
        <div id="search_add" class="search_add">
            <%--<input type="button" value="增加" class="btn_add" onclick="location.href='role_add.jsp?totalPage=3';"/>--%>
        </div>
        <!--删除的操作提示-->
        <div id="operate_result_info" class="operate_success">
            <%--<img src="../images/close.png" onclick="this.parentNode.style.display='none';"/>--%>
            删除成功！
        </div> <!--删除错误！该角色被使用，不能删除。-->
        <!--数据区域：用表格展示数据-->
        <div id="data">
            <table id="datalist">
                <tr>
                    <th>角色 ID</th>
                    <th>角色名称</th>
                    <th class="width600">拥有的权限</th>
                    <th class="td_modi"></th>
                </tr>

                <c:forEach items="${rolelist}" var="exroleinfo">
                    <tr>
                        <td>${exroleinfo.roleId}</td>
                        <td>${exroleinfo.name}</td>
                        <td>${exroleinfo.moduleName}</td>
                        <td>
                            <input type="button" value="修改" class="btn_modify"
                                   onclick="location.href='role_modi.jsp?start=${currentPage}&roleId=${exroleinfo.roleId}&name=${exroleinfo.name}&moduleName=${exroleinfo.moduleName}';"/>
                            <input type="button" value="删除" class="btn_delete"
                                   onclick="location.href='/role/role_delete?start=${currentPage}&roleId=${exroleinfo.roleId}'; deleteRole()"/>
                        </td>
                    </tr>
                </c:forEach>

            </table>
        </div>
        <!--分页-->
        <div id="pages">
            <script>
                $(function () {
                    var div = $('#pages');
                    var currentPage = ${currentPage};
                    var totalCount = ${totalCount};
                    var lastCount = currentPage - 1;
                    var nextCount = currentPage + 1;

                    var lastPage = '<a id="lastPage" href="javascript:;" onclick="location.href=\'role_list_all?start=' + lastCount + '\';">上一页</a>';
                    var nextPage = '<a id="nextPage" href="javascript:;" onclick="location.href=\'role_list_all?start=' + nextCount + '\';">下一页</a>';

                    div.append(lastPage);
                    for (var i = 1; i < totalCount / 7 + 1; i++) {
                        var button = '<a href="javascript:;" onclick="location.href=\'role_list_all?start=' + i + '\';">' + i + '</a>';
                        div.append(button);
                    }
                    div.append(nextPage);
                    if (currentPage === 1) document.getElementById('lastPage').style.display = 'none';
                    if (currentPage >= totalCount / 7) document.getElementById('nextPage').style.display = 'none';

                    var i;
                    for (i = 0; i < totalCount / 7; i++) {
                        var page = document.getElementById('pages').children[i + 2];
                        if (page.textContent == currentPage) {
                            page.className = "current_page";
                        }
                    }

                var input = '<input type="button" value="增加" class="btn_add" onclick="location.href=\'role_add.jsp?totalPage='+
                    i +'\';"/>';
                    var div_add_button = $('#search_add');
                    div_add_button.append(input);
                })
            </script>
        </div>
    </form>
</div>
<!--主要区域结束-->
<div id="footer">
    <p>[源自北美的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</p>
    <p>版权所有(C)云科技有限公司 </p>
</div>
</body>
</html>

